package com.uenpay.im.ui.old.activity.chat;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.qyx.android.protocol.BaseContentModel;
import com.qyx.android.protocol.SessionModel;
import com.uenpay.im.IMApplication;
import com.uenpay.im.ui.old.activity.contacts.UserDetailActivity;
import com.uenpay.im.ui.old.activity.personal.MeDetailActivity;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @date 2016-5-27 下午7:48:00
 * @version 1.0
 * @function 会话辅助
 *
 */
public class ActivityHandle {

	/**
	 * 开始会话
	 *
	 * @param mContext
	 * @param sessionId
	 *            会话id
	 * @param sessionType
	 *            会话类型(1 | 2)
	 * @param operationType
	 *            会话业务类型(公众号3)
	 * @param strangerName
	 *            会话名称
	 * @param unreadMsgCount
	 *            该会话未读消息数量
	 * @param forwardMsg
	 *            转发对象
	 */
	public static void startChat(Context mContext, long sessionId, int sessionType, int operationType, String strangerName,
			int unreadMsgCount, BaseContentModel forwardMsg) {
		if (sessionId == 0 || mContext == null)
			return;
		Bundle bundle = new Bundle();
		SessionModel sessionModel = new SessionModel();
		sessionModel.setSessionId(sessionId);
		sessionModel.setSessionType(sessionType);
		sessionModel.setOperationType(operationType);
		bundle.putParcelable("session", sessionModel);
		bundle.putString("stranger_name", strangerName);
		bundle.putInt("unread_msg_count", unreadMsgCount);
		bundle.putParcelable("forwardMsg", forwardMsg);
		Intent intent = new Intent(mContext, ChatActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtras(bundle);
		mContext.startActivity(intent);
	}

	/**
	 * Activity 跳转页面
	 *
	 * @param activity
	 * @param clazz
	 *            跳转目标类
	 * @param bundle
	 *            参数 无参数为null
	 * @param requestCode
	 *            请求Code | 无需返回：-1
	 */
	public static void startActivity(Activity activity, Class<?> clazz, Bundle bundle, int requestCode) {
		if (clazz == null || activity == null)
			return;
		Intent intent = new Intent(activity, clazz);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		if (requestCode < 0) {
			activity.startActivity(intent);
		} else {
			activity.startActivityForResult(intent, requestCode);
		}

	}

	/**
	 * 跳转用户详情
	 *
	 * @param activity
	 * @param cust_id
	 *            用户id
	 */
	public static void startUserDetailActivity(Activity activity, String cust_id) {
		Intent intent = null;
		if (cust_id.equals(IMApplication.getCustId())) {
			intent = new Intent(activity, MeDetailActivity.class);
		} else {
			intent = new Intent(activity, UserDetailActivity.class);
			intent.putExtra("cust_id", cust_id + "");
		}
		activity.startActivity(intent);
	}

}
